<html>
<head><meta charset="utf-8"><title>MIRI false positive in hecs? · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html">MIRI false positive in hecs?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="183463278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/183463278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benjamin Saunders <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#183463278">(Dec 14 2019 at 23:31)</a>:</h4>
<p>I have some code which copies values into/out of unaligned memory, but isn't doing much else funny before MIRI throws a fit: "trying to reborrow for SharedReadOnly, but parent tag &lt;143201&gt; does not have an appropriate item in the borrow stack". Full code/output here: <a href="https://github.com/Ralith/hecs/pull/4/checks?check_run_id=348893958" target="_blank" title="https://github.com/Ralith/hecs/pull/4/checks?check_run_id=348893958">https://github.com/Ralith/hecs/pull/4/checks?check_run_id=348893958</a>. Am I missing some UB here?</p>



<a name="183463999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/183463999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> comex <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#183463999">(Dec 14 2019 at 23:55)</a>:</h4>
<p>If possible you should try to come up with a self-contained playground test case.</p>



<a name="183464059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/183464059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> comex <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#183464059">(Dec 14 2019 at 23:56)</a>:</h4>
<p>(though it would be nice if miri could explain its errors better)</p>



<a name="183464387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/183464387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> comex <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#183464387">(Dec 15 2019 at 00:07)</a>:</h4>
<p>I think basically, miri does not like when you index into an array, and then take that pointer and go out of bounds of the array element: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=21d5640dfcba3c293c6889cb0ddfe137" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=21d5640dfcba3c293c6889cb0ddfe137">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=21d5640dfcba3c293c6889cb0ddfe137</a></p>



<a name="183464402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/183464402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> comex <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#183464402">(Dec 15 2019 at 00:07)</a>:</h4>
<p>Probably, instead of <code>self.storage[self.cursor].as_mut_ptr()</code>, you want <code>self.storage.as_mut_ptr().offset(self.cursor)</code></p>



<a name="183464443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/183464443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> comex <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#183464443">(Dec 15 2019 at 00:08)</a>:</h4>
<p>I'm not sure what the rules around this are supposed to be, though</p>



<a name="183464446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/183464446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> comex <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#183464446">(Dec 15 2019 at 00:08)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span></p>



<a name="183470217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/183470217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benjamin Saunders <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#183470217">(Dec 15 2019 at 03:33)</a>:</h4>
<p>no way to run miri on the playground, is there? miri doesn't work at all on my system (<a href="https://github.com/mozilla/nixpkgs-mozilla/issues/198" target="_blank" title="https://github.com/mozilla/nixpkgs-mozilla/issues/198">https://github.com/mozilla/nixpkgs-mozilla/issues/198</a>) so it's difficult for me to refine</p>



<a name="183470704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/183470704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> comex <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#183470704">(Dec 15 2019 at 03:50)</a>:</h4>
<p><span class="user-mention" data-user-id="216097">@Benjamin Saunders</span>  It's in the right menu under "tools" (no idea why it's there)</p>



<a name="183470722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/183470722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Benjamin Saunders <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#183470722">(Dec 15 2019 at 03:51)</a>:</h4>
<p>ahah, thanks, that'll be a big help! and the indexing indeed seems to have been the key</p>



<a name="184057875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/184057875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#184057875">(Dec 22 2019 at 15:05)</a>:</h4>
<blockquote>
<p>no way to run miri on the playground, is there? miri doesn't work at all on my system (<a href="https://github.com/mozilla/nixpkgs-mozilla/issues/198" target="_blank" title="https://github.com/mozilla/nixpkgs-mozilla/issues/198">https://github.com/mozilla/nixpkgs-mozilla/issues/198</a>) so it's difficult for me to refine</p>
</blockquote>
<p>thanks for pointing me to that, I had no idea Miri's sysroot detection is in conflict with nix's overlays. Would be good to find a way to fix that.</p>



<a name="184057916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI%20false%20positive%20in%20hecs%3F/near/184057916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MIRI.20false.20positive.20in.20hecs.3F.html#184057916">(Dec 22 2019 at 15:06)</a>:</h4>
<p>regarding the original issue, I agree with what <span class="user-mention" data-user-id="198590">@comex</span> said -- when you get a pointer to an array element that's a pointer <em>to that element</em> only, not usable for its neighbors.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>